//
//  MJExtensionVC.m
//  Objc进阶Demo
//
//  Created by Don't update on 2018/8/10.
//  Copyright © 2018年 Don't update. All rights reserved.
//

#import "MJExtensionVC.h"
#import <MJExtension.h>
#import "Store.h"
//http://119.29.230.249/GLZ/storesinfo.php?area=1
@interface MJExtensionVC ()

@end

@implementation MJExtensionVC



- (void)viewDidLoad {
    [super viewDidLoad];
    [self getStoreData];
    
    // Do any additional setup after loading the view.
}



-(void)getStoreData{
    NSURL *url = [NSURL URLWithString:@"http://119.29.230.249/GLZ/storesinfo.php?area=1"];

    //创建一个请求对象
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    //获得回话对象
    NSURLSession *session = [NSURLSession sharedSession];
    
    //根据回话对象创建一个Task(发送请求)
    /*
     参数1: 请求对象
     */
    
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        
        NSLog(@"网络响应:response: %@",response);
        
        NSArray *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
      
//        NSLog(@"success:------%@",dict[1]);
        Store *store = [Store mj_objectWithKeyValues:dict[1]];
        
        NSLog(@"-------%@",store.title);
        
    }];
    
    [dataTask resume];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
